package com.project.service.impl;

import com.project.bean.CarBean;
import com.project.bean.ManBean;
import com.project.mapper.IManMapper;
import com.project.service.IManService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ManServiceImpl extends BaseService implements IManService {
    @Override
    public List<ManBean> findAll() {
        SqlSession session = this.getSession();
        IManMapper mapper = session.getMapper(IManMapper.class);
        List<ManBean> list=mapper.findAll();
        session.close();
        return list;
    }

    @Override
    public void addMan(ManBean manBean, List<CarBean> carList) {
            SqlSession session= this.getSession();
            IManMapper mapper=session.getMapper(IManMapper.class);
            mapper.addMan(manBean);
            mapper.addCarList(manBean.getId(), carList);
            session.commit();
            session.close();
    }

    @Override
    public void cascadingDel(int manID) {
        SqlSession session = this.getSession();
        IManMapper mapper = session.getMapper(IManMapper.class);
        mapper.cascadingDel(manID);
        session.commit();
        session.close();
    }

    @Override
    public void setNullDel(int manID) {
        SqlSession session = this.getSession();
        IManMapper mapper = session.getMapper(IManMapper.class);
        mapper.setNullDel(manID);
        session.commit();
        session.close();
    }

    @Override
    public ManBean findById(int manID) {
        SqlSession session= this.getSession();
        IManMapper mapper = session.getMapper(IManMapper.class);
        ManBean man = mapper.findById(manID);
        session.close();
        return man;
    }
}
